<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="5" :sm="24">
            <a-form-item label="账号">
              <a-input v-model="queryParam.loginName"placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="!advanced && 6 || 24" :sm="24">
            <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button style="margin-left: 8px" @click="resert()">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="$refs.modal.add()">添加用户</a-button>
    </div>
    <s-table
      ref="table"
      :row-key="record => record.id" 
      size="default"
      :columns="columns"
      :data="loadData"
      showPagination="auto" bordered>
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="info(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm
            title="是否删除该条记录?"
            @confirm="confirm(record)"
            @cancel="cancel"
            okText="是"
            cancelText="否"
          >
            <a href="#">删除</a>
          </a-popconfirm>
          </a-badge>
        </template>
      </span>
    </s-table>
    <user-list-modal ref="modal" @ok="handleOk"></user-list-modal>

  </a-card>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import { postAxiosUrl ,getAllUser} from '@/api/manage'
  import UserListModal from './modules/userListModal'

export default {
  name: 'TableList',
  components: {
    STable,
    Ellipsis,
    UserListModal
  },
  data () {
    return {
      showZero:false,
      offset:[10,-3],
      mdl: {},
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        { title: '序号', scopedSlots: { customRender: 'serial' } },
        { title: '账号', dataIndex: 'loginName' },
        { title: '昵称', dataIndex: 'name' },
        { title: '上次登录时间', dataIndex: 'loginDate'},
        { title: '注册时间', dataIndex: 'createDate'},
        { title: '操作', dataIndex: 'action', width: '150px',scopedSlots: { customRender: 'action' }}
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        console.log('loadData.parameter', parameter)
        return getAllUser(Object.assign(parameter, this.queryParam))
          .then(res => {
            return res.result
          })
      },
      selectedRows: [],
      options: {
      },
      optionAlertShow: false
    }
  },
  filters: {
  },
  created () {
    console.log('-------------this--------',this)
  },
  methods: {
    resert(){
      this.queryParam = {}
      this.$refs.table.refresh(true)
    },
    info (record) {
      this.$refs.modal.edit(record)
    },
    confirm (record) {
      const me = this
            postAxiosUrl('delUser', {id : record.id})
              .then(res => {
                me.$refs.table.refresh(true)
              })
    },
    cancel(e) {
    },
    handleOk () {
      this.$refs.table.refresh()
    },
    resetSearchForm () {
      this.queryParam = {
        date: moment(new Date())
      }
    }
  }
}
</script>